"""
用户相关的API数据模型
"""
from typing import Optional
from datetime import datetime
from pydantic import BaseModel, Field


class UserBase(BaseModel):
    """用户基础模型"""
    nickname: Optional[str] = Field(None, max_length=50, description="昵称")
    avatar: Optional[str] = Field(None, max_length=500, description="头像URL")
    email: Optional[str] = Field(None, max_length=100, description="邮箱")


class UserCreate(UserBase):
    """创建用户模型"""
    openid: str = Field(..., max_length=100, description="微信openid")


class UserUpdate(UserBase):
    """更新用户模型"""
    pass


class User(UserBase):
    """用户返回模型"""
    id: int
    openid: str
    is_active: bool
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True


class UserProfile(BaseModel):
    """用户档案模型"""
    id: int
    nickname: Optional[str]
    avatar: Optional[str]
    email: Optional[str]
    diary_count: int = Field(0, description="日记总数")
    total_words: int = Field(0, description="总字数")
    created_at: datetime

    class Config:
        from_attributes = True